import requests
import json

def newStrategyTracks(payload_dict):
    #url = "http://106.53.146.53:7001/api/ccSmartStrategy/saveStrategyTracksForTag/invoke"
    url = "http://172.20.151.110:8001/api/ccSmartStrategy/saveStrategyTracksForTag/invoke"
    headers = {
        'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
    }
    response = requests.post(url, json=payload_dict, headers=headers)
    print("Status:", response.status_code)
    try:
        span_id = response.json().get("data", {}).get("spanId", "")
        print(f"\"{span_id}\",")
        return span_id
    except:
        print("解析失败")
        return None

# 主函数
if __name__ == "__main__":
    tags = [
        "爆笑",
        "悲伤",
        "轻松",
        "催泪",
        "减压",
        "感人",
        "安静",
        "孤单",
        "焦虑",
        "感动",
        "怀念",
        "舒缓",
        "冥想",
        "欢乐",
        "心动",
        "紧张",
        "治愈",
        "热血",
        "励志",
        "温馨",
        "浪漫"
    ]
    payload_list = [
        {
            "tagNames": tag,
            "genType": "2",
            "category": "电影",
            "tagCombin": "标签+分类"
        }
        for tag in tags
    ]

    # 打印 JSON 格式（双引号）
    print(json.dumps(payload_list, ensure_ascii=False, indent=2))
    # 每2条数据分组，并逐组调用接口
    batch_size = 5
    for i in range(0, len(payload_list), batch_size):
        batch = payload_list[i:i + batch_size]
        #print(f"\n--- 发送第 {i // batch_size + 1} 批（共 {len(batch)} 条）---")
        #print(json.dumps(batch, ensure_ascii=False, indent=2))

        # 调用接口
        newStrategyTracks(batch)